********************************************************************************************************************
*****Do-file for Table A14
*****Who is mobilized to vote by short text messages? Evidence from a nationwide field experiment with young voters
********************************************************************************************************************
*****Last edited 24/6/5
********************************************************************************************************************
*****Ado packages needed: estout
********************************************************************************************************************

clear all

*Programs to calculate group differences with standard errors and stars
capture program drop, myrepost
program myrepost, eclass
ereturn repost b=`1'
ereturn repost V=`2'
ereturn scalar df_r=`3'
end

capture program drop mystars
program mystars, eclass
local d_stars=string(`1', "%9.3f")
local pval=ttail(`3',abs(`1'/`2'))*2

if `pval'<=0.01 {
local d_stars="`d_stars'"+"***"		
}

if `pval'>0.01 & `pval'<=0.05  {
local d_stars="`d_stars'"+"**"		
}

if `pval'>0.05 & `pval'<=0.1  {
local d_stars="`d_stars'"+"*"		
}

local se_stars=string(`2', "%9.3f")

local se_stars="("+"`se_stars'"+")"

ereturn local d_stars="`d_stars'"
ereturn local se_stars="`se_stars'"


end

*Use data
use \data\dataforanalysis230522_v2.dta, clear
*Set basecategory
fvset base 8 moses1d

*************************************************
*****TABLE A14
*************************************************





eststo clear

label variable treated "Treated"



eststo pooled: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool, cluster(kunta19)
estadd local controls "Yes"
estimates store pooled
qui: mean voted22adv if treated==0 & e(sample)==1
scalar umean1s=r(table)[1,1]
local umean1: di %9.3f scalar(umean1s) 

eststo neutral: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated1!=., cluster(kunta19)
estadd local controls "Yes"
estimates store neutral
qui: mean voted22adv if treated==0 & e(sample)==1
scalar umean2s=r(table)[1,1]
local umean2: di %9.3f scalar(umean2s) 


eststo expressive: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated2!=., cluster(kunta19)
estadd local controls "Yes"
estimates store expressive
qui: mean voted22adv if treated==0 & e(sample)==1
scalar umean3s=r(table)[1,1]
local umean3: di %9.3f scalar(umean3s) 



eststo informative: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated3!=., cluster(kunta19)
estadd local controls "Yes"
estimates store informative
qui: mean voted22adv if treated==0 & e(sample)==1
scalar umean4s=r(table)[1,1]
local umean4: di %9.3f scalar(umean4s) 


********************************************************************************************************************************************************************
local titles1 `"Treatment: & Pooled & "Neutral" & "Expressive" & "Informative"\\ "'
local numbers "& (1) & (2) & (3) & (4) \\ \hline"
local emptyrow "& & & &  \\ "
local line "& & & & \hline \\ "

esttab using adv_voting.tex, keep (treated) noobs label se b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
 mlabels(none) nonumbers prehead(\begin{table}[htbp]\centering ///
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} ///
\caption{Advance and Election Day Voting} ///
\begin{tabular}{l*{4}{c}}\hline\hline) posthead(`"`titles1'"' "`titles2'" "`numbers'" \\ \multicolumn{4}{l}{\textbf{Outcome:} Voted in Advance} \\ "`emptyrow'")  ///
refcat(treated "Untreated $\bar{Y}$ &`umean1'&`umean2'&`umean3'&`umean4'\\ %", nolabel below) ///
fragment nonotes replace
eststo clear

qui: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool, cluster(kunta19)

matrix Brep1=e(b)
matrix Vrep1=e(V)
scalar df1=e(df_r)
qui: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool, cluster(kunta19)

matrix Brep2=e(b)
matrix Vrep2=e(V)
scalar df2=e(df_r)

scalar df=df1+df2

scalar diffe=Brep1[1,1]-Brep2[1,1]
scalar stde=sqrt(Vrep1[1,1]+Vrep2[1,1])


eststo pooled: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool, cluster(kunta19)
mystars diffe stde df
estadd local controls "Yes"
estimates store pooled

qui: mean voted22elday if treated==0 & e(sample)==1
scalar umean1s=r(table)[1,1]
local umean1: di %9.3f scalar(umean1s) 

qui: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated1!=., cluster(kunta19)

matrix Brep1=e(b)
matrix Vrep1=e(V)
scalar df1=e(df_r)
qui: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated1!=., cluster(kunta19)

matrix Brep2=e(b)
matrix Vrep2=e(V)
scalar df2=e(df_r)

scalar df=df1+df2

scalar diffe=Brep1[1,1]-Brep2[1,1]
scalar stde=sqrt(Vrep1[1,1]+Vrep2[1,1])

eststo neutral: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated1!=., cluster(kunta19)
mystars diffe stde df
estadd local controls "Yes"
estimates store neutral
qui: mean voted22elday if treated==0 & e(sample)==1
scalar umean2s=r(table)[1,1]
local umean2: di %9.3f scalar(umean2s) 

qui: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated2!=., cluster(kunta19)

matrix Brep1=e(b)
matrix Vrep1=e(V)
scalar df1=e(df_r)
qui: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated2!=., cluster(kunta19)

matrix Brep2=e(b)
matrix Vrep2=e(V)
scalar df2=e(df_r)

scalar df=df1+df2

scalar diffe=Brep1[1,1]-Brep2[1,1]
scalar stde=sqrt(Vrep1[1,1]+Vrep2[1,1])

eststo expressive: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated2!=., cluster(kunta19)

mystars diffe stde df
estadd local controls "Yes"
estimates store expressive
qui: mean voted22elday if treated==0 & e(sample)==1
scalar umean3s=r(table)[1,1]
local umean3: di %9.3f scalar(umean3s) 


qui: reg voted22adv treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated3!=., cluster(kunta19)

matrix Brep1=e(b)
matrix Vrep1=e(V)
scalar df1=e(df_r)
qui: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated3!=., cluster(kunta19)

matrix Brep2=e(b)
matrix Vrep2=e(V)
scalar df2=e(df_r)

scalar df=df1+df2

scalar diffe=Brep1[1,1]-Brep2[1,1]
scalar stde=sqrt(Vrep1[1,1]+Vrep2[1,1])

eststo informative: reg voted22elday treated molincome female age foreign i.moses1d firstvote i.mohighschool if treated3!=., cluster(kunta19)

mystars diffe stde df
estadd local controls "Yes"
estimates store informative
qui: mean voted22elday if treated==0 & e(sample)==1
scalar umean4s=r(table)[1,1]
local umean4: di %9.3f scalar(umean4s) 



esttab, keep (treated) noobs label se b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("controls Controls "  "N Observations" "d_stars Differences" "se_stars \phantom{se}") ///
sfmt(%9.3f %9.0fc %9.3f) mlabels(none) nonumbers prefoot(\hline)  posthead("`emptyrow'" \multicolumn{4}{l}{\textbf{Outcome:} Voted on Election Day} \\ "`emptyrow'")  ///
refcat(treated "Untreated $\bar{Y}$ &`umean1'&`umean2'&`umean3'&`umean4'\\ %", nolabel below) postfoot(\hline\hline \\ \end{tabular} \\ \end{table}) fragment append nonotes 
